package cn.cs.service;

import cn.cs.mapper.AgentMapper;
import cn.cs.pojo.Agent;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
public class AgetnService {

    //@Autowired
    @Resource
    private AgentMapper agentMapper;

    @RequestMapping(value = "/getAgentById", method = RequestMethod.POST)
    public Agent getAgentById(@RequestParam("id") String id) throws Exception{
        return agentMapper.getAgentById(id);
    }

    @RequestMapping(value = "/getAgentByNamePhone", method = RequestMethod.POST)
    public List<Agent> getAgentByNamePhone(@RequestParam("name") String name, @RequestParam("person") String person, @RequestParam("phone") String phone) throws Exception{
        return agentMapper.getAgentByNamePhone(name, person, phone);
    }

    @RequestMapping(value = "/getAgentByCode", method = RequestMethod.POST)
    public Agent getAgentByCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getAgentByCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentByPCode", method = RequestMethod.POST)
    public List<Agent> getAgentByPCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getAgentByPCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentListByMap", method = RequestMethod.POST)
    public List<Agent> getAgentListByMap(@RequestBody Map<String, Object> param) throws Exception{
        return agentMapper.getAgentListByMap(param);
    }

    @RequestMapping(value = "/getAgentAllListByMap", method = RequestMethod.POST)
    public List<Agent> getAgentAllListByMap(@RequestBody Map<String, Object> param) throws Exception{
        return agentMapper.getAgentAllListByMap(param);
    }

    @RequestMapping(value = "/getAgentCountByMap", method = RequestMethod.POST)
    public Integer getAgentCountByMap(@RequestBody Map<String, Object> param) throws Exception{
        return agentMapper.getAgentCountByMap(param);
    }

    @RequestMapping(value = "/addAgent", method = RequestMethod.POST)
    public Integer addAgent(@RequestBody Agent agent) throws Exception{
        return agentMapper.insertAgent(agent);
    }

    @RequestMapping(value = "/modifyAgent", method = RequestMethod.POST)
    public Integer modifyAgent(@RequestBody Agent agent) throws Exception{
        return agentMapper.updateAgent(agent);
    }

    @RequestMapping(value = "/deleteAgentById", method = RequestMethod.POST)
    public Integer deleteAgentById(@RequestParam("id") String id) throws Exception{
        return agentMapper.deleteAgentById(id);
    }

    @RequestMapping(value = "/getMaxCode", method = RequestMethod.POST)
    public Long getMaxCode() throws Exception{
        return agentMapper.getMaxCode();
    }


    @RequestMapping(value = "/getAgentAreaListById", method = RequestMethod.POST)
    public List<Map<String, Object>> getAgentAreaListById(@RequestParam("agentId") String agentId) throws Exception{
        return agentMapper.getAgentAreaListById(agentId);
    }

    @RequestMapping(value = "/addAgentArea", method = RequestMethod.POST)
    public Integer addAgentArea(@RequestBody Map<String, Object> param) throws Exception{
        return agentMapper.insertAgentArea(param);
    }

    @RequestMapping(value = "/deleteAgentAreaById", method = RequestMethod.POST)
    public Integer deleteAgentAreaById(@RequestParam("id") String id) throws Exception{
        return agentMapper.deleteAgentAreaById(id);
    }

    @RequestMapping(value = "/getProvinceList", method = RequestMethod.POST)
    public List<Map<String, Object>> getProvinceList() throws Exception{
        return agentMapper.getProvinceList();
    }

    @RequestMapping(value = "/getCityListByPid", method = RequestMethod.POST)
    public List<Map<String, Object>> getCityListByPid(@RequestParam("agentId") String agentId) throws Exception{
        return agentMapper.getCityListByPid(agentId);
    }

    @RequestMapping(value = "/getAreaListByPid", method = RequestMethod.POST)
    public List<Map<String, Object>> getAreaListByPid(@RequestParam("agentId") String agentId, @RequestBody List<Map<String, Object>> list) throws Exception{
        return agentMapper.getAreaListByPid(agentId, list);
    }

    @RequestMapping(value = "/getAreasListByPid", method = RequestMethod.POST)
    public List<Map<String, Object>> getAreasListByPid(@RequestParam("agentId") String agentId) throws Exception{
        return agentMapper.getAreasListByPid(agentId);
    }

    @RequestMapping(value = "/getUserNumberByAgentCode", method = RequestMethod.POST)
    public Long getUserNumberByAgentCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getUserNumberByAgentCode(invitationCode);
    }

    @RequestMapping(value = "/getShopNumberByAgentCode", method = RequestMethod.POST)
    public Long getShopNumberByAgentCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getShopNumberByAgentCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentBNumberByAgentCode", method = RequestMethod.POST)
    public Long getAgentBNumberByAgentCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getAgentBNumberByAgentCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentNumberByAgentCode", method = RequestMethod.POST)
    public Long getAgentNumberByAgentCode(@RequestParam("invitationCode") String invitationCode) throws Exception{
        return agentMapper.getAgentNumberByAgentCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentAreaTwoById", method = RequestMethod.POST)
    public String getAgentAreaTwoById(@RequestParam("id") String id){
        return agentMapper.getAgentAreaTwoById(id);
    }

    @RequestMapping(value = "/getAgentBYPhone", method = RequestMethod.POST)
    public Map<String, Object> getAgentBYPhone(@RequestParam("phone") String phone) throws Exception{
        return agentMapper.getAgentBYPhone(phone);
    }

    @RequestMapping(value = "/getAreaByProvinceId", method = RequestMethod.POST)
    public String getAreaByProvinceId(@RequestParam("provinceId") String provinceId){
        return agentMapper.getAreaByProvinceId(provinceId);
    }

    @RequestMapping(value = "/getFirstByProvinceId", method = RequestMethod.POST)
    public Map<String, Object> getFirstByProvinceId(@RequestParam("id") String id) throws Exception{
        return agentMapper.getFirstByProvinceId(id);
    }

    @RequestMapping(value = "/insertAgentAreaList", method = RequestMethod.POST)
    public Integer insertAgentAreaList(@RequestBody List<Map<String, Object>> list){
        return agentMapper.insertAgentAreaList(list);
    }

    @RequestMapping(value = "/updateAgentType", method = RequestMethod.POST)
    public Integer updateAgentType(@RequestParam("parent_invitation_code") String parent_invitation_code, @RequestParam("agent_area") String agent_area, @RequestParam("old_invitation_code") String old_invitation_code, @RequestParam("id") String id)throws Exception{
        return agentMapper.updateAgentType(parent_invitation_code, agent_area, old_invitation_code, id);
    }

    @RequestMapping(value = "/getAgentAreaByInvitationCode", method = RequestMethod.POST)
    public Map<String, Object> getAgentAreaByInvitationCode(@RequestParam("parent_invitation_code") String parent_invitation_code, @RequestParam("agent_area") String agent_area)throws Exception{
        return agentMapper.getAgentAreaByInvitationCode(parent_invitation_code,agent_area);
    }

    @RequestMapping(value = "/getAgentAreaById", method = RequestMethod.POST)
    public Map<String, Object> getAgentAreaById(@RequestParam("id") String id)throws Exception{
        return agentMapper.getAgentAreaById(id);
    }

    @RequestMapping(value = "/getAreaProvince", method = RequestMethod.POST)
    public List<Map<String, Object>> getAreaProvince(@RequestParam("agentId") String agentId)throws Exception{
        return agentMapper.getAreaProvince(agentId);
    }

    @RequestMapping(value = "/getAreaCity", method = RequestMethod.POST)
    public List<Map<String, Object>> getAreaCity(@RequestParam("agentId") String agentId, @RequestParam("pId") String pId)throws Exception{
        return agentMapper.getAreaCity(agentId, pId);
    }

    @RequestMapping(value = "/getAreaArea", method = RequestMethod.POST)
    public List<Map<String, Object>> getAreaArea(@RequestParam("agentId") String agentId, @RequestParam("pId") String pId)throws Exception{
        return agentMapper.getAreaArea(agentId, pId);
    }

    @RequestMapping(value = "/getAgentByArea", method = RequestMethod.POST)
    public List<Map<String, Object>> getAgentByArea(@RequestParam("area") String area)throws Exception{
        return agentMapper.getAgentByArea(area);
    }

    @RequestMapping(value = "/getAgentABIdByCode", method = RequestMethod.POST)
    public Map<String, String> getAgentABIdByCode(@RequestParam("invitationCode") String invitationCode)throws Exception{
        return agentMapper.getAgentABIdByCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentByOnlyArea", method = RequestMethod.POST)
    public List<Agent> getAgentByOnlyArea(@RequestParam("area") String area)throws Exception{
        return agentMapper.getAgentByOnlyArea(area);
    }

    @RequestMapping(value = "/checkInvitationCode", method = RequestMethod.POST)
    public int checkInvitationCode(@RequestParam("invitationCode") String invitationCode){
        return agentMapper.checkInvitationCode(invitationCode);
    }

    @RequestMapping(value = "/getAgentAreaAll", method = RequestMethod.POST)
    public List<Map<String, Object>> getAgentAreaAll(){
        return agentMapper.getAgentAreaAll();
    }

    @RequestMapping(value = "/getAgentAreasByAgentId", method = RequestMethod.POST)
    public List<Map<String, Object>> getAgentAreasByAgentId(@RequestParam("agentId") String agentId) throws Exception{
        return agentMapper.getAgentAreaByAgentId(agentId);
    }
}
